﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using eProject.Logic;
using eProject.Model;

namespace eProject.View
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        private readonly Tasks _tasks = new Tasks();
        public Window1()
        {
           
            InitializeComponent();

            var tasks = new ObservableCollection<Task>();

            var task1 = new Task("Task1", "The first task", 20);
            var task2 = new Task("Task2", "The second task", 30);
            var task3 = new Task("Task3", "The third task", 10);

            tasks.Add(task1);
            tasks.Add(task2);
            tasks.Add(task3);

            var empl1 = new Employee("Vasia", "Pupkin", "Vasilievich", "vp@vp.com", "+7-812-223-23-23");
            var empl2 = new Employee("Lena", "Pupkina", "Ivanovna", "lp@vp.com", "+7-812-223-23-23");

            task1.CreateActivity(empl1, new Period(new DateTime(2010, 02, 01), new DateTime(2010, 02, 03)), 4);
            task1.CreateActivity(empl2, new Period(new DateTime(2010, 02, 02), new DateTime(2010, 02, 05)), 4);
            task2.CreateActivity(empl1, new Period(new DateTime(2010, 02, 02), new DateTime(2010, 02, 03)), 6);
            task3.CreateActivity(empl1, new Period(new DateTime(2010, 02, 03), new DateTime(2010, 02, 05)), 4);
            task3.CreateActivity(empl2, new Period(new DateTime(2010, 02, 02), new DateTime(2010, 02, 04)), 4);
            DataContext = tasks;

        }     
        
    }

    class PeriodToLeftPositionConverter : IValueConverter
    {
        private static readonly DateTime Begin = new DateTime(2010, 02, 01);
        private const int PixelsPerDay = 30;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var period = (Period)value;
            var result = (period.Begin - Begin).TotalDays * PixelsPerDay;

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

    class PeriodToWidthConverter : IValueConverter
    {
        private const int PixelsPerDay = 30;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var period = (Period) value;
            var result = (period.End - period.Begin).TotalDays * PixelsPerDay;
            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return null;
        }
    }

}
